package cn.crism.blog.service.impl;

import cn.crism.blog.entity.Blogroll;
import cn.crism.blog.repository.BlogrollRepository;
import cn.crism.blog.service.BlogrollService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: Crism
 * @Date: 上午9:32 18/2/12
 * @Description:
 */

@Service
public class BlogrollServiceImpl implements BlogrollService {
    @Autowired
    private BlogrollRepository blogrollRepository;

    @Override
    public Boolean createBlogroll(Blogroll blogroll) {
        if (blogrollRepository.exists(blogrollRepository.save(blogroll).getBlogId())){
            return true;
        }
        return false;
    }

    @Override
    public Boolean removeBlogroll(Integer blogrollId) {
        if (blogrollRepository.existsById(blogrollId)){
            blogrollRepository.delete(blogrollId);
            return true;
        }
        return false;
    }

    @Override
    public Boolean modifyBlogroll(Blogroll blogroll) {
        if (blogrollRepository.exists(blogroll.getBlogId())){
            blogrollRepository.save(blogroll);
            return true;
        }
        return false;
    }

    @Override
    public List<Blogroll> getBlogrolls() {
        return blogrollRepository.findAll();
    }
}
